package gui.customizepanel;

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class JInboxPanel extends JPanel {

	private static final long serialVersionUID = 0xA1L;

	private JPanel pn_mailread;
	private JPanel pn_newmail;
	private JScrollPane scroll_new_mail;
	private JScrollPane scroll_read_mail;
	private JSplitPane sp_inbox;
	private JTable tbl_newmail;
	private JTable tbl_readmail;

	private static JInboxPanel instance;

	public static final JInboxPanel getInstance() {
		if (instance == null)
			return instance = new JInboxPanel();
		return instance;
	}

	private JInboxPanel() {
		initComponents();
	}

	private void newComps() {
		sp_inbox = new JSplitPane();
		pn_newmail = new JPanel();
		scroll_new_mail = new JScrollPane();
		tbl_newmail = new JTable();
		pn_mailread = new JPanel();
		scroll_read_mail = new JScrollPane();
		tbl_readmail = new JTable();
	}

	@SuppressWarnings("serial")
	private void setCompsProperties() {
		sp_inbox.setOrientation(JSplitPane.VERTICAL_SPLIT);
		sp_inbox.setPreferredSize(new Dimension(1100, 676));

		pn_newmail.setBorder(BorderFactory.createTitledBorder("New Mail"));
		pn_newmail.setMinimumSize(new Dimension(1100, 200));
		pn_newmail.setPreferredSize(new Dimension(1100, 200));

		tbl_newmail.setModel(new DefaultTableModel(new Object[][] {

		}, new String[] { "From", "Subject", "Attachment", "Date" }) {
			boolean[] canEdit = new boolean[] { false, false, false, false };

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		scroll_new_mail.setViewportView(tbl_newmail);
	}

	private void pn_newmailLayout() {

		GroupLayout pn_newmailLayout = new GroupLayout(pn_newmail);
		pn_newmail.setLayout(pn_newmailLayout);
		pn_newmailLayout.setHorizontalGroup(pn_newmailLayout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addComponent(scroll_new_mail, GroupLayout.Alignment.TRAILING,
						GroupLayout.DEFAULT_SIZE, 1088, Short.MAX_VALUE));
		pn_newmailLayout.setVerticalGroup(pn_newmailLayout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addComponent(scroll_new_mail,
				GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE));

		pn_newmail.setSize(pn_newmail.getPreferredSize());

		sp_inbox.setTopComponent(pn_newmail);
	}

	private void pn_mailreadLayout() {
		pn_mailread.setBorder(BorderFactory.createTitledBorder("Read Mail"));
		pn_mailread.setPreferredSize(new Dimension(1100, 470));

		tbl_readmail.setModel(new DefaultTableModel(new Object[][] {

		}, new String[] { "From", "Subject", "Attachment", "Date" }));
		scroll_read_mail.setViewportView(tbl_readmail);

		GroupLayout pn_mailreadLayout = new GroupLayout(pn_mailread);
		pn_mailread.setLayout(pn_mailreadLayout);
		pn_mailreadLayout.setHorizontalGroup(pn_mailreadLayout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addComponent(scroll_read_mail, GroupLayout.DEFAULT_SIZE, 1088,
						Short.MAX_VALUE));
		pn_mailreadLayout.setVerticalGroup(pn_mailreadLayout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addComponent(scroll_read_mail, GroupLayout.DEFAULT_SIZE, 441,
						Short.MAX_VALUE));

		sp_inbox.setSize(sp_inbox.getPreferredSize());

		sp_inbox.setRightComponent(pn_mailread);
	}

	private void mainLayout() {
		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addComponent(sp_inbox,
				GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addComponent(sp_inbox,
				GroupLayout.DEFAULT_SIZE, 670, Short.MAX_VALUE));
	}

	private void initComponents() {
		newComps();
		setCompsProperties();
		pn_newmailLayout();
		pn_mailreadLayout();
		mainLayout();

		setMinimumSize(new Dimension(1100, 670));

	}

}
